package edu.unf.cen6940.dao;

import edu.unf.cen6940.domain.Generatedproduct;

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.skyway.spring.util.dao.AbstractJpaDao;

import org.springframework.dao.DataAccessException;

import org.springframework.stereotype.Repository;

import org.springframework.transaction.annotation.Transactional;

/**
 * DAO to manage Generatedproduct entities.
 * 
 */
@Repository("GeneratedproductDAO")
@Transactional
public class GeneratedproductDAOImpl extends AbstractJpaDao<Generatedproduct>
		implements GeneratedproductDAO {

	/**
	 * Set of entity classes managed by this DAO.  Typically a DAO manages a single entity.
	 *
	 */
	private final static Set<Class<?>> dataTypes = new HashSet<Class<?>>(Arrays.asList(new Class<?>[] { Generatedproduct.class }));

	/**
	 * EntityManager injected by Spring for persistence unit rms
	 *
	 */
	@PersistenceContext(unitName = "rms")
	private EntityManager entityManager;

	/**
	 * Instantiates a new GeneratedproductDAOImpl
	 *
	 */
	public GeneratedproductDAOImpl() {
		super();
	}

	/**
	 * Get the entity manager that manages persistence unit 
	 *
	 */
	public EntityManager getEntityManager() {
		return entityManager;
	}

	/**
	 * Returns the set of entity classes managed by this DAO.
	 *
	 */
	public Set<Class<?>> getTypes() {
		return dataTypes;
	}

	/**
	 * JPQL Query - findGeneratedproductByProductName
	 *
	 */
	@Transactional
	public Set<Generatedproduct> findGeneratedproductByProductName(String productName) throws DataAccessException {

		return findGeneratedproductByProductName(productName, -1, -1);
	}

	/**
	 * JPQL Query - findGeneratedproductByProductName
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Generatedproduct> findGeneratedproductByProductName(String productName, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findGeneratedproductByProductName", startResult, maxRows, productName);
		return new LinkedHashSet<Generatedproduct>(query.getResultList());
	}

	/**
	 * JPQL Query - findGeneratedproductByPrimaryKey
	 *
	 */
	@Transactional
	public Generatedproduct findGeneratedproductByPrimaryKey(Integer generatedProductId) throws DataAccessException {

		return findGeneratedproductByPrimaryKey(generatedProductId, -1, -1);
	}

	/**
	 * JPQL Query - findGeneratedproductByPrimaryKey
	 *
	 */

	@Transactional
	public Generatedproduct findGeneratedproductByPrimaryKey(Integer generatedProductId, int startResult, int maxRows) throws DataAccessException {
		try {
			Query query = createNamedQuery("findGeneratedproductByPrimaryKey", startResult, maxRows, generatedProductId);
			return (edu.unf.cen6940.domain.Generatedproduct) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findAllGeneratedproducts
	 *
	 */
	@Transactional
	public Set<Generatedproduct> findAllGeneratedproducts() throws DataAccessException {

		return findAllGeneratedproducts(-1, -1);
	}

	/**
	 * JPQL Query - findAllGeneratedproducts
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Generatedproduct> findAllGeneratedproducts(int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAllGeneratedproducts", startResult, maxRows);
		return new LinkedHashSet<Generatedproduct>(query.getResultList());
	}

	/**
	 * JPQL Query - findGeneratedproductByGeneratedProductId
	 *
	 */
	@Transactional
	public Generatedproduct findGeneratedproductByGeneratedProductId(Integer generatedProductId) throws DataAccessException {

		return findGeneratedproductByGeneratedProductId(generatedProductId, -1, -1);
	}

	/**
	 * JPQL Query - findGeneratedproductByGeneratedProductId
	 *
	 */

	@Transactional
	public Generatedproduct findGeneratedproductByGeneratedProductId(Integer generatedProductId, int startResult, int maxRows) throws DataAccessException {
		try {
			Query query = createNamedQuery("findGeneratedproductByGeneratedProductId", startResult, maxRows, generatedProductId);
			return (edu.unf.cen6940.domain.Generatedproduct) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findGeneratedproductByProductDescription
	 *
	 */
	@Transactional
	public Set<Generatedproduct> findGeneratedproductByProductDescription(String productDescription) throws DataAccessException {

		return findGeneratedproductByProductDescription(productDescription, -1, -1);
	}

	/**
	 * JPQL Query - findGeneratedproductByProductDescription
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Generatedproduct> findGeneratedproductByProductDescription(String productDescription, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findGeneratedproductByProductDescription", startResult, maxRows, productDescription);
		return new LinkedHashSet<Generatedproduct>(query.getResultList());
	}

	/**
	 * JPQL Query - findGeneratedproductByProductDescriptionContaining
	 *
	 */
	@Transactional
	public Set<Generatedproduct> findGeneratedproductByProductDescriptionContaining(String productDescription) throws DataAccessException {

		return findGeneratedproductByProductDescriptionContaining(productDescription, -1, -1);
	}

	/**
	 * JPQL Query - findGeneratedproductByProductDescriptionContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Generatedproduct> findGeneratedproductByProductDescriptionContaining(String productDescription, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findGeneratedproductByProductDescriptionContaining", startResult, maxRows, productDescription);
		return new LinkedHashSet<Generatedproduct>(query.getResultList());
	}

	/**
	 * JPQL Query - findGeneratedproductByProductNameContaining
	 *
	 */
	@Transactional
	public Set<Generatedproduct> findGeneratedproductByProductNameContaining(String productName) throws DataAccessException {

		return findGeneratedproductByProductNameContaining(productName, -1, -1);
	}

	/**
	 * JPQL Query - findGeneratedproductByProductNameContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Generatedproduct> findGeneratedproductByProductNameContaining(String productName, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findGeneratedproductByProductNameContaining", startResult, maxRows, productName);
		return new LinkedHashSet<Generatedproduct>(query.getResultList());
	}

	/**
	 * Used to determine whether or not to merge the entity or persist the entity when calling Store
	 * @see store
	 * 
	 *
	 */
	public boolean canBeMerged(Generatedproduct entity) {
		return true;
	}
}
